 /**
 * 逻辑、功能相关描述: <br>
 *
 * @author 付湘辉  <br>
 * 编写日期：2009-1-13  <br>
 */
package com.ce.pms.occupation.service;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.SQLQuery;
import org.junit.Assert;
import org.junit.Test;

import com.ce.pms.DBUnitTool;
import com.ce.pms.base.dao.IPmsBaseHibernateDao;
import com.ce.pms.charge.service.IChargeRecordProcessor;
import com.ce.pms.charge.vo.ChargeRecordVO;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.util.BeanUtil;

/**
 * 	名称: com.ce.pms.occupation.service.OccupationChargeRecordProcessorImplT <br>
 * 入伙费用处理器单元测试
 *
 * @author  付湘辉  <br>
 * Created on： 2009-1-13 <br>
 * @author <br>
 * update on： <br>
 * why: <br>
 */
public class OccupationChargeRecordProcessorImplT extends DBUnitTool {
	private IChargeRecordProcessor occupationChargeRecordProcessor;
	
	/**
	 * 功能描述:  <br>
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2009-1-13  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	@Test
	public void testHandleChargeRecords() {
		try {
			initOccupationChargeRecordProcessor();
			//正常业务
			// 初始化数据,chargeRecordId是已存的一个未处理的入伙预缴费用记录
			IPmsBaseHibernateDao pmsBaseHibernateDao =  (IPmsBaseHibernateDao)applicationContext.getBean("pmsBaseHibernateDao");
			String sql = "SELECT * FROM FEE_CHARGE_RECORD FCR WHERE FCR.CHARGE_RECORD_ID=? ";
			SQLQuery sqlQuery = pmsBaseHibernateDao.createSQLQuery(sql);
			sqlQuery.setLong(0, chargeRecordId);
			Object obj = sqlQuery.uniqueResult();
			Assert.assertNotNull(obj);
			Object[] objs = (Object[])obj;
			ChargeRecordVO tmpVo= new ChargeRecordVO();
			tmpVo.setKeyword(chargeRecordId);
			tmpVo.setHouseId(objs[1]==null?null:((BigInteger)objs[1]).longValue());
			tmpVo.setHandleYn(objs[2]==null?null:(String)objs[2]);
			tmpVo.setOperationType(objs[3]==null?null:(String)objs[3]);
			tmpVo.setSum(objs[4]==null?null:(BigDecimal)objs[4]);
			tmpVo.setRemark(objs[5]==null?null:(String)objs[5]);
			tmpVo.setBizModule(objs[6]==null?null:(String)objs[6]);
			tmpVo.setBizType(objs[7]==null?null:(String)objs[7]);
			tmpVo.setBizId(objs[8]==null?null:((BigInteger)objs[8]).longValue());
			tmpVo.setCreator(objs[9]==null?null:((BigInteger)objs[9]).longValue());
			tmpVo.setSysDate(objs[10]==null?null:(Date)objs[10]);
			tmpVo.setModifier(operator);
			tmpVo.setModifyDate(objs[12]==null?null:(Date)objs[12]);
			tmpVo.setEnterAccountMethod(objs[13]==null?null:(String)objs[13]);
			tmpVo.setBusinessId(objs[14]==null?null:((BigInteger)objs[14]).longValue());
			tmpVo.setItemName(objs[15]==null?null:(String)objs[15]);

			List<ChargeRecordVO> chargeRecords = new ArrayList<ChargeRecordVO>();
			ChargeRecordVO chargeRecordVO = new ChargeRecordVO();
			BeanUtil.convertVoAsDo(tmpVo, chargeRecordVO);
			chargeRecords.add(chargeRecordVO);
			//执行处理过程测试
			Boolean res = occupationChargeRecordProcessor.handleChargeRecords(houseId, operator, businessCodeId, chargeRecords);
			Assert.assertTrue(res);
			for (ChargeRecordVO recordVO : chargeRecords) {
				Assert.assertTrue(SysrefcodeDO.CONSTANTS_DIGITAL_ONE.equals(recordVO.getHandleYn()));
			}
			//清理数据
//			sql = "UPDATE FEE_CHARGE_RECORD SET HANDLE_YN=?,MODIFIER=?,MODIFY_DATE=? WHERE CHARGE_RECORD_ID=? ";
//			sqlQuery = pmsBaseHibernateDao.createSQLQuery(sql);
//			sqlQuery.setString(0, tmpVo.getHandleYn());
//			sqlQuery.setLong(1, tmpVo.getModifier());
//			sqlQuery.setDate(2, tmpVo.getModifyDate());
//			sqlQuery.setLong(3, chargeRecordId);
//			sqlQuery.executeUpdate();
			//传入不合法参数
		} catch (Exception e) {
			super.dealException(e);
		}
	}
	
	private  static Long houseId = 3l;
	
	private  static Long operator = 1l;
	
	private  static Long businessCodeId = 8l;
	
	private  static Long chargeRecordId = 20l;

	
	private void initOccupationChargeRecordProcessor(){
		if (occupationChargeRecordProcessor == null) {
			occupationChargeRecordProcessor = (IChargeRecordProcessor)applicationContext.getBean("occupationChargeRecordProcessor");
		}
	}
}
